# -*- coding: utf-8 -*-
# @Time    : 2019/10/17 14:30
# @Author  : LiHaowen
# @Email   : lihaowen2017@163.com
# @File    : an_error_parameter.py


def add(a, b):
    a += b  # 传递了可变序列就将a修改了(+=)
    return a


class Company:
    def __init__(self, name, staffs=[]):
        self.name = name
        self.staffs = staffs

    def add(self, staff_name):
        self.staffs.append(staff_name)

    def remove(self, staff_name):
        self.staffs.remove(staff_name)


if __name__ == '__main__':
    com1 = Company("com1", ["b1", "b2", "b3"])  # 传递列表进去，列表可以被修改
    print(Company.__init__.__defaults__)
    com1.add("b4")
    com1.remove("b1")
    print(com1.staffs)
    com2 = Company("com2")
    com2.add("b5")
    print(com2.staffs)  # ['b5']
    print(Company.__init__.__defaults__)
    com3 = Company("com3")
    com3.add("b6")
    print(Company.__init__.__defaults__)
    print(com2.staffs)  # ['b5', 'b6']
    print(com3.staffs)  # ['b5', 'b6']
    print(com2.staffs is com3.staffs)  # True
    # 结果打印错误原因: com2和com3 没有传递staffs列表参数，所以他们使用的是共同的默认list
    # (staffs指向Company.__init__.__defaults__) com1传递了staffs列表所以不是指向默认列表了
    a = 1
    b = 2
    c = add(a, b)
    print(c)
    print(a, b)

    a = [1, 2]
    b = [3, 4]
    c = add(a, b)
    print(c)  # [1, 2, 3, 4]
    print(a, b)  # [1, 2, 3, 4]

    a = (1, 2)
    b = (3, 4)
    c = add(a, b)
    print(c)
    print(a, b)
